<%#
 Copyright 2013-2020 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
os:
  - linux
services:
  - docker
language: node_js
node_js:
  - "<%= NODE_VERSION %>"
cache:
  directories:
    - node
    - node_modules
<%_ if (buildTool === 'maven') { _%>
    - $HOME/.m2
<%_ } else if (buildTool === 'gradle') { _%>
    - $HOME/.gradle
<%_ } _%>
env:
  global:
    - NODE_VERSION=<%= NODE_VERSION %>
    - SPRING_OUTPUT_ANSI_ENABLED=ALWAYS
    - SPRING_JPA_SHOW_SQL=false
    - JHI_DISABLE_WEBPACK_LOGS=true
    - NG_CLI_ANALYTICS="false"
<%_ if (buildTool === 'maven') { _%>
    - MAVEN_USER_HOME=$HOME/.m2/repository/
<%_ } _%>
before_install:
  - |
    if [[ $JHI_JDK = '8' ]]; then
      echo '*** Using OpenJDK 8'
    else
      echo '*** Using OpenJDK 11 by default'
      sudo add-apt-repository ppa:openjdk-r/ppa -y
      sudo apt-get update -q
      sudo apt-get install -y openjdk-11-jdk -y
      sudo update-java-alternatives -s java-1.11.0-openjdk-amd64
      java -version
    fi
  - java -version
  - sudo /etc/init.d/mysql stop
  - sudo /etc/init.d/postgresql stop
  - nvm install $NODE_VERSION
  - npm install -g npm
  - node -v
  - npm -v
install:
  - <%= clientPackageManager %> install
script:
<%_ if (buildTool === 'maven') { _%>
  - chmod +x mvnw
  - ./mvnw -ntp checkstyle:check
  - ./mvnw -ntp clean verify
<%_ } else if (buildTool === 'gradle') { _%>
  - chmod +x gradlew
  - ./gradlew checkstyleNohttp
  - ./gradlew clean test integrationTest
<%_ } _%>
<%_ if (!skipClient) { _%>
  <%_ if (buildTool === 'maven') { _%>
  - ./mvnw -ntp com.github.eirslett:frontend-maven-plugin:<%= clientPackageManager %> -Dfrontend.<%= clientPackageManager %>.arguments='run <%= frontTestCommand %>' -Dmaven.repo.local=$MAVEN_USER_HOME
  <%_ } else if (buildTool === 'gradle') { _%>
  - ./gradlew <%= clientPackageManager %>_run_<%= frontTestCommand %> -PnodeInstall --no-daemon
  <%_ } _%>
<%_ } _%>
<%_ if (buildTool === 'maven') { _%>
  <%_ if (cicdIntegrations.includes('sonar')) { _%>
  - if [ $TRAVIS_PULL_REQUEST == "false" ]; then ./mvnw -ntp org.jacoco:jacoco-maven-plugin:prepare-agent initialize sonar:sonar <% if (sonarOrga) { %>-Dsonar.organization=<%= sonarOrga %> <% } %>-Dsonar.host.url=<%= sonarUrl %> -Dsonar.login=$SONAR_TOKEN; fi
  <%_ } _%>
  - ./mvnw -ntp verify -Pprod -DskipTests
  <%_ if (cicdIntegrations.includes('heroku')) { _%>
  - ./mvnw -ntp com.heroku.sdk:heroku-maven-plugin:2.0.5:deploy -DskipTests -Pprod -Dheroku.buildpacks=heroku/jvm -Dheroku.appName=<%= herokuAppName %>
  <%_ } _%>
<%_ } else if (buildTool === 'gradle') { _%>
  <%_ if (cicdIntegrations.includes('sonar')) { _%>
  - if [ $TRAVIS_PULL_REQUEST == "false" ]; then ./gradlew sonarqube --no-daemon <% if (sonarOrga) { %>-Dsonar.organization=<%= sonarOrga %> <% } %>-Dsonar.host.url=<%= sonarUrl %> -Dsonar.login=$SONAR_TOKEN; fi
  <%_ } _%>
  - ./gradlew bootJar -Pprod -x test
  <%_ if (cicdIntegrations.includes('heroku')) { _%>
  - ./gradlew deployHeroku
  <%_ } _%>
<%_ } _%>
notifications:
  webhooks:
    on_success: change  # options: [always|never|change] default: always
    on_failure: always  # options: [always|never|change] default: always
    on_start: false     # default: false
